//
//  NewFriendCell.m
//  ChangChat
//
//  Created by Cocoa on 2019/9/27.
//  Copyright © 2019 yibai. All rights reserved.
//

#import "NewFriendCell.h"

@implementation NewFriendCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
//        self.nameLabel.backgroundColor = UIColor.redColor;
    }
    return self;
}
- (void)setupUI {
    
    self.iconImageView = UIImageView.new;
    self.nameLabel = [UILabel k_labelWithFontSize:15 textColor:UIColor.k_t2Color];
    self.nameLabel.highlightedTextColor = UIColor.k_t1Color;
    self.descLabel = [UILabel k_labelWithFontSize:13 textColor:UIColor.k_t3Color];
    self.descLabel.numberOfLines = 0;
    
    self.actionContentView = [UIView new];
    self.actionContentView.layer.cornerRadius = 15;
    self.actionContentView.layer.masksToBounds = YES;
    self.actionContentView.backgroundColor = UIColor.k_hexColor(0xEBF3FF);
    self.agreeBtn = UIButton.k_initType(UIButtonTypeCustom).k_title(@"同意").k_titleColor(UIColor.whiteColor).k_bgImgColor(UIColor.k_t1Color).k_font([UIFont systemFontOfSize:12]);
    self.rejectBtn = UIButton.k_initType(UIButtonTypeCustom).k_title(@"拒绝").k_titleColor(UIColor.whiteColor).k_bgImgColor(UIColor.k_hexColor(0x5397FF)).k_font([UIFont systemFontOfSize:12]);
    self.statusLabel = [UILabel k_labelWithText:@"已拒绝" fontSize:12 textColor:UIColor.k_t4Color];
    self.statusLabel.highlightedTextColor = UIColor.k_t1Color;
    
    [self.actionContentView addSubview:self.agreeBtn];
    [self.actionContentView addSubview:self.rejectBtn];
    [self.actionContentView addSubview:self.statusLabel];
    
    [self.pContentView addSubview:self.iconImageView];
    [self.pContentView addSubview:self.nameLabel];
    [self.pContentView addSubview:self.descLabel];
    [self.pContentView addSubview:self.actionContentView];
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.top.mas_offset(11);
        make.size.mas_equalTo(CGSizeMake(40, 40));
        make.bottom.mas_offset(-11).priorityLow();
    }];
    self.iconImageView.layer.cornerRadius = 20;
    self.iconImageView.layer.masksToBounds = YES;
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconImageView.mas_right).offset(5);
        make.top.equalTo(self.iconImageView).offset(5);
        make.right.equalTo(self.actionContentView.mas_left).offset(-10);
    }];
    [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel);
        make.right.equalTo(self.nameLabel);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(5);
        make.bottom.lessThanOrEqualTo(self.pContentView).offset(-11);
    }];
    [self.actionContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-15);
        make.size.mas_equalTo(CGSizeMake(80, 30));
        make.centerY.equalTo(self.nameLabel);
    }];
    
    [self.agreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_offset(0);
    }];
    [self.rejectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_offset(0);
    }];
    [@[self.agreeBtn, self.rejectBtn] mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:0 leadSpacing:0 tailSpacing:0];
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.actionContentView);
    }];
    
    
    self.selectedBackgroundView = [[UIView alloc] initWithFrame:self.bounds];
    self.selectedBackgroundView.backgroundColor = UIColor.whiteColor;
    self.backgroundColor =
    self.contentView.backgroundColor = global_viewBackgroundColor;
    
    self.iconImageView.image = UIImage.k_imgName(@"placeholder_user");
    self.nameLabel.text = @"李四";
}

- (void)setFriendItem:(FriendItem *)friendItem {
    _friendItem = friendItem;
    
    [self.iconImageView sd_setImageWithURL:friendItem.avatar.toURL placeholderImage:UIImage.k_imgName(@"placeholder_user")];
    self.nameLabel.text = friendItem.displayName;
    self.descLabel.text = friendItem.content;
    
    
    if (friendItem.status == 1) {
        self.agreeBtn.hidden =
        self.rejectBtn.hidden = NO;
        self.statusLabel.hidden = YES;
    } else {
        self.agreeBtn.hidden =
        self.rejectBtn.hidden = YES;
        self.statusLabel.hidden = NO;
        
        if (friendItem.status == 0) {
            self.statusLabel.highlighted = YES;
            self.statusLabel.text = @"等待验证";
        } else {
            self.statusLabel.highlighted = NO;
            if (friendItem.status == 2) {
                self.statusLabel.text = @"已同意";
            } else if (friendItem.status == 3) {
                self.statusLabel.text = @"已拒绝";
            }
        }
    }
}

@end
